package YHATM;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Menu extends JFrame implements ActionListener{

    private static final Menu menu = new Menu();

    private JPanel m1,m2;
    private JButton cun,qu,cha,zhuan,cpasswd,exit,back;
    private JDialog tip;
    private JLabel err;

    public static void showMenu() {
        menu.setVisible(true);
    }

    private Menu() {
        this.setTitle("ATM模拟系统");
        this.setSize(500, 300);
        this.setLocation(500, 300);
        this.setLayout(null);
        this.setResizable(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        m1 = new JPanel();
        m1.setBounds(0, 0, 500, 30);
        m1.setBackground(new Color(150,150,150));
        m1.add(new JLabel("选择业务"));
        this.add(m1);
        m2 = new JPanel();
        m2.setBounds(0, 30, 500, 250);
        m2.setBackground(new Color(224,224,224));
        m2.setLayout(null);
        this.add(m2);
        cun = new JButton("存款");
        qu = new JButton("取款");
        cha = new JButton("查询");
        zhuan = new JButton("转账");
        cpasswd = new JButton("更改密码");
        exit = new JButton("退出");
        back = new JButton("返回");
        m2.add(cun);
        m2.add(qu);
        m2.add(cha);
        m2.add(zhuan);
        m2.add(cpasswd);
        m2.add(exit);
        cun.setBounds(25,30,100,30);
        qu.setBounds(360,30,100,30);
        cha.setBounds(25,90,100,30);
        zhuan.setBounds(360,90,100,30);
        cpasswd.setBounds(25,150,100,30);
        exit.setBounds(360,150,100,30);
        cun.addActionListener(this);
        qu.addActionListener(this);
        cha.addActionListener(this);
        zhuan.addActionListener(this);
        cpasswd.addActionListener(this);
        exit.addActionListener(this);
        back.addActionListener(this);
        err = new JLabel("暂不开通本服务");
        err.setBounds(90, 20, 150, 30);
        back.setBounds(105, 60, 80, 30);
        tip = new JDialog(this, "转账", true);
        tip.setSize(300,150);
        tip.setLayout(null);
        tip.setLocation(600,250);
        tip.add(err);
        tip.add(back);
        setVisible(true);
    }
    public void actionPerformed(ActionEvent e) {
        Object source = e.getSource();
        if(source==cun) {
            this.dispose();
            new Cun();
        }else if(source==qu) {
            this.dispose();
            new Qu();
        }else if(source==cha) {
            this.dispose();
            try {
                new Cha();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }else if(source==zhuan) {
            tip.setVisible(true);
        }else if(source==cpasswd) {
            this.dispose();
            new Change();
        }else if(source==exit) {
            Test.login();
            this.dispose();
            new Login();
            JOptionPane.showMessageDialog(null,"请记得取走你的银行卡");
        }else if(source==back) {
            tip.dispose();
        }
    }
}